<?php

/**
 * 所有接口返回的ret 默认cmd = 接口名 , status = 0(成功)
 */

function test_test_sql()
{
	$ret = array() ;
	$ret[] = sql_field_types("user_info") ;
	$ret[] = sql_field_flags("user_info") ;
	return $ret ;
}
// 操作管理员登陆
function test_login($json)
{
	$nm = get_jsonValue($json,"name") ;
	$ps = get_jsonValue($json,"pass") ;
		
	$ret = array() ;
	$now = sql_fetch_one("select * from admin where `username` = '$nm' and `userpass` = '$ps'") ;
	if (is_array($now) && array_key_exists('username' , $now)){
		$nowname = $now['username'] ;
		if ($nm != $nowname){
			$ret['state'] = 0 ;		// 失败
		}else{
			$ret['state'] = 1 ;		// 登陆成功
			$ret['permissions'] =  $now['permissions'] ;
			$ret['permissions_json'] =  $now['permissions_json'] ;
		}
	}else{
		$ret['state'] = 0 ;		// 失败
	}
	return $ret ;
}
function test_login_v2($json)
{
	$loginname = get_jsonValue($json,"loginname") ;
	$timestamp = get_jsonValue($json,"timestamp") ;
	$key 	   = get_jsonValue($json,"key") ;
	
	$now = sql_fetch_one("select * from admin_info where `username` = '$loginname'") ;
	if (is_null($now) == true || is_array($now) == false){
		$ret['state'] = 0 ;
		$ret['message'] = "无效用户，请联系管理员解决。" ;
		return $ret ;
	}
	
	$md5key = md5($loginname.$timestamp.$now['password_hash'].$now['auth_key']) ;
	if (strlen($key) == 0 || $key != $md5key){
		$ret['state'] = 0 ;
		$ret['message'] = "校验失败，请联系管理员解决。" ;
		return $ret ;
	}
	
	$ret['state'] = 1 ;		// 登陆成功
	$ret['permissions_json'] =  $now['permissions_json'] ;
	return $ret ;
}
// 获取某个管理员的权限
function test_get_admin_permiss($json)
{
	$nm = get_jsonValue($json,"name") ;
	$now = sql_fetch_one("select * from admin where `username` = '$nm'") ;
	
	if (is_array($now) == false)
	{
		$ret['state'] = 0 ;
		$ret['message'] = "用户不存在" ;
	}else{
		$ret['state'] = 1 ;		// 登陆成功
		$ret['permissions_json'] =  $now['permissions_json'] ;
	}
	return $ret ;
}
// 设置某个管理员的权限
function test_set_admin_permiss($json)
{
	$nm = get_jsonValue($json,"name") ;
	$pers = json_encode(get_jsonValue($json,"json") , JSON_UNESCAPED_UNICODE) ;
	
	sql_query("update admin set `permissions_json` = '$pers' where `username` = '$nm'") ;	
	
	return test_get_all_Permiss($json) ;
}
function test_set_admin_permiss_v2($json)
{
	$nm = get_jsonValue($json,"name") ;
	$pers = json_encode(get_jsonValue($json,"json") , JSON_UNESCAPED_UNICODE) ;
	
	sql_query("update admin_info set `permissions_json` = '$pers' where `username` = '$nm'") ;	
	
	return test_get_all_Permiss_v2($json) ;
}
function test_get_all_Permiss($json)
{
	$ret = array() ;
	$ret['state'] = 1 ;
	$ret['permiss'] = sql_fetch_rows("select * from admin") ;
	return $ret ;	
}
function test_get_all_Permiss_v2($json)
{
	$ret = array() ;
	$ret['state'] = 1 ;
	$ret['permiss'] = sql_fetch_rows("select `username` , `permissions_json` from admin_info") ;
	return $ret ;
}
function test_add_admin($json)
{
	$nm = get_jsonValue($json,"username") ;
	$ps = get_jsonValue($json,"userpass") ;
	$ret = array() ;
	
	$now = sql_fetch_one("select * from admin where `username` = '$nm'") ;
	if (is_array($now) == true)
	{
		$ret['state'] = 0 ;
		$ret['message'] = "请删除或修改用户名:" . $nm ;
		return $ret ;
	}
	
	sql_query("insert into `admin`(`username` , `userpass` , `permissions_json`) values ('$nm' , '$ps' , '')") ;
	
	return test_get_all_Permiss($json) ;
}
function test_admin_change_name($json)
{
	$om = get_jsonValue($json , "oldname") ;
	$nm = get_jsonValue($json,"username") ;
	$ps = get_jsonValue($json,"userpass") ;
	
	sql_query("update admin set `username` = '$nm' , `userpass` = '$ps' where `username` = '$om'") ;
	
	return test_get_all_Permiss($json) ;
}
function test_admin_delete($json)
{
	$nm = get_jsonValue($json,"username") ;
	
	sql_query("delete from admin where `username` = '$nm'") ;
	
	return test_get_all_Permiss($json) ;
}
// 获取品种的所有类型
function test_type($json)
{
	$ret = array() ;
	$ret['typeList'] = sql_fetch_rows("select * from prf_type") ;
	return $ret ;	
}

// 获取某类的所有商品
function test_getTypeFileList($json)
{
	$type = get_jsonValue($json,"id") ;
	$pagination = get_jsonValue($json,"pagination") ;
	$offset = get_jsonValue($pagination,"offset") ;		if (intval($offset) < 1)	$offset = 1 ;
	$limit  = get_jsonValue($pagination,"limit") ;		if (intval($limit) < 1)		$limit = 20 ;
	$start = ($offset - 1) * $limit ;	
	
	$filter_name = trim(get_jsonValue($json,"filter_name")) ;
	$nm_ft = "" ;
	if ($filter_name != ""){
		$nm_ft = " and `name` like '%$filter_name%'" ;
	}
	
	$filter_brand = intval(get_jsonValue($json,"filter_brand")) ;
	if ($filter_brand > 0){		
		$allcount = sql_fetch_one_cell("select count(DISTINCT p.img_tz_id) from sys_item s inner join base_sys_preview p on s.id = p.item_id where s.brand_id = $filter_brand") ;
		
		$ret = array() ;
		$ret['data']['pagination'] = array() ;
		util_set_PAGINATION($ret['data']['pagination'] , $allcount , $limit , $offset) ;		

		if ($allcount == 0){
			$ret['fileList'] = array() ;
		}else{
			$lists = sql_fetch_rows("select DISTINCT p.img_tz_id from sys_item s inner join base_sys_preview p on s.id = p.item_id where s.brand_id = $filter_brand order by p.`img_tz_id` desc limit $start , $limit") ;
			$se_ids = "" ; $dh = "" ;			
			foreach($lists as $s){
				$se_ids .= $dh.$s['img_tz_id'] ; $dh = "," ;
			}
			
			$ret['fileList'] = sql_fetch_rows("select * from sys_image where id in ($se_ids) order by `id`") ;
			foreach ($ret['fileList'] as &$im){
				$im['url'] = $GLOBALS['URL_IMG_HEAD'] . $im['url'] ; 
			}
		}
		return $ret ;
	}
	
	
	
	$allcount = sql_fetch_one_cell("select count(id) from `sys_image` where `type` = $type  $nm_ft") ;

	$ret = array() ;
	$ret['data']['pagination'] = array() ;
	util_set_PAGINATION($ret['data']['pagination'] , $allcount , $limit , $offset) ;
	
	$ret['fileList'] = sql_fetch_rows("select * from sys_image where `type` = $type  $nm_ft order by `id` desc , `name` limit $start , $limit") ;
	foreach ($ret['fileList'] as &$im){
		$im['url'] = $GLOBALS['URL_IMG_HEAD'] . $im['url'] ; 
	}
	return $ret ;
}
// 更改一组图片的分类
function test_changeTypeFileListType($json)
{
	$ty = get_jsonValue($json,"changety") ;
	$arr = get_jsonValue($json,"idlist") ;	
	foreach($arr as $id){	
		sql_query("update sys_image set `type` = '$ty' where `id` = '$id'") ;		
	}
	$ret = array() ;
	return $ret ;
}
// 删除一组选中的图片(删除图片)
function test_delete_select_pic($json)
{
	$ret = array() ;
	$arr = get_jsonValue($json,"idlist") ;	
	$err = "" ; $dh = "" ;
	$delnum = 0 ;
	foreach($arr as $id){
		$img = sql_fetch_one("select * from sys_image where `id` = '$id'") ;
		if (is_array($img) && array_key_exists("url", $img)){
			if (sql_check("select * from base_sys_fabric where img_small_id = '$id' or img_thumb_id = '$id' or img_url_id = '$id' limit 1")){
				$err .= $dh."([$id] in table [base_sys_fabric])" ;	$dh = "," ;
				continue ;
			}
			if (sql_check("select * from base_sys_material where img_small_id = '$id' or img_thumb_id = '$id' or img_url_id = '$id' limit 1")){
				$err .= $dh."([$id] in table [base_sys_material])" ;	$dh = "," ;
				continue ;
			}
			if (sql_check("select * from base_sys_preview where img_small_id = '$id' or img_thumb_id = '$id' or img_url_id = '$id' or img_tz_id = '$id' limit 1")){
				$err .= $dh."([$id] in table [base_sys_preview])" ;	$dh = "," ;
				continue ;
			}
			if (sql_check("select * from base_sys_preview_angle where img_small_id = '$id' or img_thumb_id = '$id' or img_url_id = '$id' limit 1")){
				$err .= $dh."([$id] in table [base_sys_preview_angle])" ;	$dh = "," ;
				continue ;
			}
			if (sql_check("select * from sys_home_banner where img_small_id = '$id' or img_thumb_id = '$id' or img_url_id = '$id' limit 1")){
				$err .= $dh."([$id] in table [sys_home_banner])" ;	$dh = "," ;
				continue ;
			}
			if (sql_check("select * from sys_item where img_small_id = '$id' or img_thumb_id = '$id' or img_url_id = '$id' limit 1")){
				$err .= $dh."([$id] in table [sys_item])" ;	$dh = "," ;
				continue ;
			}
			if (sql_check("select * from taozhuang where img_small_id = '$id' or img_thumb_id = '$id' or img_url_id = '$id' limit 1")){
				$err .= $dh."([$id] in table [taozhuang])" ;	$dh = "," ;
				continue ;
			}
			if (sql_check("select * from taozhuang_pos where img_id = '$id' limit 1")){
				$err .= $dh."([$id] in table [taozhuang_pos])" ;	$dh = "," ;
				continue ;
			}
			if (intval($id) == 2464 || intval($id) == 2465){
				$err .= $dh."([$id] default head)" ;	$dh = "," ;
				continue ;
			}
			sql_query("delete from sys_image where `id` = '$id'") ;
			if (sql_check("select * from sys_image where `id` = '$id'") == false){
				$delnum += 1 ;
				$file_path = $GLOBALS['upload_Path'] . $img['url'] ;
				unlink($file_path) ;
			}else{
				$err .= $dh."([$id] del err)" ;	$dh = "," ;
			}
		}else{
			$err .= $dh."([$id] not find)" ;	$dh = "," ;
		}
	}
	$ret['oknum'] = count($arr) - $delnum ;
	$ret['delnum'] = $delnum ;
	$ret['errmess'] = $err ;
	return $ret ;
}
// 删除选中的类型
function test_delete_prf_type($json)
{
	$ret = array() ;
	$ty = get_jsonValue($json,"changety") ;
	$one = sql_fetch_one("select * from prf_type where `id` = '$ty' and father = -1") ;
	if (is_array($one) && array_key_exists("addr", $one)){
		$url = $one['addr'] ;
		$alls = sql_fetch_rows("select * from prf_type where addr like '$url%' and father = -1") ; 
		foreach ($alls as $a){
			$ty = $a['id'] ;
			if (sql_check("select * from sys_image where type = '$ty' limit 1")){
				$ret['ok'] = 10 ;
				$ret['errmess'] = "此类型/或子类有被sys_image中引用" ;
				return $ret ;
			}
		}
		foreach ($alls as $a){
			$ty = $a['id'] ;
			sql_query("delete from prf_type where `id` = '$ty'") ;
		}
		$ret['ok'] = 1 ;
		return $ret ;
	}else{
		$ret['ok'] = 9 ;
		$ret['errmess'] = "分类数据不能删除/没有此类型" ;
		return $ret ;
	}
	
	$ret['ok'] = 1 ;
	return $ret ;
}

// 添加一个新的单品
function test_add_item($json)
{
	$nm = get_jsonValue($json,"name") ;
	$price_base = get_jsonValue($json,"price_base") ;
	$price_custom = get_jsonValue($json,"price_custom") ;
	$app_return =  get_jsonValue($json,"app_return") ;
	$filter_name =  trim(get_jsonValue($json,"filter_name")) ;
	
	$offset = get_jsonValue($json,"offset") ;
	$limit =  get_jsonValue($json,"limit") ;
	
	sql_insert("INSERT INTO `sys_item` (`name`, `price_base`,`price_custom`,`app_return`) VALUES ('$nm','$price_base', '$price_custom', '$app_return')") ;

	$test = new test_bk() ;
	$ret = $test->get_table_for_page($offset , $limit , true , $filter_name , "sys_item") ;
	return $ret ;
}
function test_edit_item($json)
{
	$id = get_jsonValue($json,"id") ;
	$nm = get_jsonValue($json,"name") ;
	$price_base = get_jsonValue($json,"price_base") ;
	$price_custom = get_jsonValue($json,"price_custom") ;
	$app_return =  get_jsonValue($json,"app_return") ;
	$filter_name =  trim(get_jsonValue($json,"filter_name")) ;
	
	$offset = get_jsonValue($json,"offset") ;
	$limit =  get_jsonValue($json,"limit") ;
	
	sql_query("update `sys_item` set `name` = '$nm', `price_base` = '$price_base',`price_custom` = '$price_custom',`app_return` = '$app_return' where `id` = '$id'") ;
	
	$test = new test_bk() ;
	$ret = $test->get_table_for_page($offset , $limit , false , $filter_name , "sys_item") ;
	return $ret ;
}

// 添加一个新的类型
function text_add_itemType($json)
{
	$name = get_jsonValue($json,"name") ;
	$path = get_jsonValue($json,"path") ;
	
	if (sql_check("select * from `prf_type` where `addr` = '$path'")){
		$ret = array() ;
		$ret['addok'] = -10 ;
		return $ret ;
	}
	
	$maxid = intval(sql_fetch_one_cell("select max(`id`) from `prf_type` where `id` < 1000000")) + 1 ;
	sql_insert("INSERT INTO `prf_type` (`id` , `typename`, `addr`) VALUES ('$maxid','$name','$path')") ;
	$ret = array() ;
	if (sql_check("select * from `prf_type` where `id` = '$maxid'")){
		$ret['addok'] = 1 ;
		$ret['typeList'] = sql_fetch_rows("select * from prf_type") ;
	}else{
		$ret['addok'] = 0 ;
	}
	return $ret ;
}


/**
 * TODO 下边是首页测试函数
 */
function test_get_home($json)
{
	$type = get_jsonValue($json,"type") ;
	$where = "where `type` = '$type'  order by `top_time` desc , `create_time` desc" ;
	
	$pagination = get_jsonValue($json,"pagination") ;
	$offset = get_jsonValue($pagination,"offset") ;
	$limit  = get_jsonValue($pagination,"limit") ;
	$filter_name = trim(get_jsonValue($pagination,"filter_name")) ;
	
	$test = new test_bk() ;
	$ret = $test->get_table_for_page($offset , $limit , false , $filter_name , "sys_home_banner" , $where) ;
	return $ret ;		
}
// 获取设计师列表信息
function test_get_designer_message($json)
{
	$ret = array() ;
	$ret['designer'] = sql_fetch_rows("select `id` , `username` as 'name' from user_info where `user_type` = 2") ;
	return $ret ;
}
// 提交更改首页基本信息
function test_commit_home_data($json)
{
	$id 			= get_jsonValue($json,"id") ;
	$name 			= get_jsonValue($json,"name") ;
	$type 			= get_jsonValue($json,"type") ;
	$designer_id 	= get_jsonValue($json,"designer_id") ;
	$description 	= get_jsonValue($json,"description") ;
	$useing 		= get_jsonValue($json,"useing") ;
	$url			= get_jsonValue($json,"url") ;
	$action			= get_jsonValue($json,"action") ;
	
	$addsql = "" ;
	if ($action == 'set' || $action == 'item'){
		$action_id = intval($url) ;
		$addsql = " , `action` = '$action' , `action_id` = '$action_id' " ;
	}else{
		$addsql = " , `action` = '' , `action_id` = '0' , `url` = '$url' " ;
	}
	
	sql_query("update `sys_home_banner` set `name` = '$name' , `type` = '$type' , designer_id = '$designer_id' , description = '$description' , useing = '$useing'  $addsql where `id` = '$id'") ;
	
	$test = new test_bk() ;
	$ret = array() ;	
	$ret['result'] = 1 ;	
	$ret['data'] = $test->global_getImageAndDesigner(sql_fetch_one("select * from `sys_home_banner` where `id` = '$id'")) ;
	return $ret ;	
}
// 创建新的首页基本信息
function test_create_home_data($json)
{
	$name 			= get_jsonValue($json,"name") ;
	$type 			= get_jsonValue($json,"type") ;
	$designer_id 	= get_jsonValue($json,"designer_id") ;
	$description 	= get_jsonValue($json,"description") ;
	$useing 		= get_jsonValue($json,"useing") ;
	$url			= get_jsonValue($json,"url") ;
	$action			= get_jsonValue($json,"action") ;
	
	$newid = sql_insert("insert into `sys_home_banner`(`name` , `type` , `designer_id` , `description` , `useing` , `url` , `create_time`) values ('$name' , '$type' , '$designer_id' , '$description' , '$useing' , '$url' , unix_timestamp())") ;
	if ($action == 'set' || $action == 'item'){
		$action_id = intval($url) ;
		sql_query("update `sys_home_banner` set `action` = '$action' , `action_id` = '$action_id' where `id` = '$newid'") ;
	}
	
	$test = new test_bk() ;
	$ret = array() ;	
	$ret['result'] = 1 ;
	$ret['data'] = $test->global_getImageAndDesigner(sql_fetch_one("select * from `sys_home_banner` where `id` = '$newid'")) ;
	return $ret ;	
}
// 套装或其他条目加入首页轮播或推荐
function test_add_item_home_page($json)
{
	$type 			= get_jsonValue($json,"type") ;
	$action			= get_jsonValue($json,"action") ;
	$action_id		= get_jsonValue($json,"action_id") ;
	$name 			= get_jsonValue($json,"name") ;
	$img_small_id	= get_jsonValue($json,"img_small_id") ;
	$img_thumb_id	= get_jsonValue($json,"img_thumb_id") ;
	$img_url_id		= get_jsonValue($json,"img_url_id") ;
	
	$id = intval(sql_fetch_one_cell("select `id` from `sys_home_banner` where `type` = '$type' and `action` = '$action' and `action_id` = '$action_id' ")) ;
	
	if ($id > 0)
	{
		sql_query("update `sys_home_banner` set `name` = '$name' , `img_small_id` = '$img_small_id' , `img_thumb_id` = '$img_thumb_id' , `img_url_id` = '$img_url_id'  where `id` = '$id'") ;
	}else{
		sql_insert("insert into `sys_home_banner`(`name` , `type` , `useing` , `action` , `action_id` , `create_time` , `img_small_id` , `img_thumb_id` , `img_url_id`) values ('$name' , '$type' , '1' , '$action' , '$action_id' , unix_timestamp() , '$img_small_id' , '$img_thumb_id' , '$img_url_id')") ;
	}
	$ret = array() ;	
	$ret['result'] = 1 ;
	return $ret ;	
}

// 修改设计师信息
function test_commit_designer($json)
{
	$ret = array() ;	
	$ret['result'] = 0 ;
	$ret['memo'] = "此后台不能修改." ;
	return $ret ;
}
// 创建新的设计师名称
function test_create_new_designer($json)
{
	$ret = array() ;	
	$ret['result'] = 0 ;
	$ret['memo'] = "此后台不能创建新用户." ;
	return $ret ;
}
// 更改某个表的默认名称
function test_change_table_images_name($json)
{
	$id 			= get_jsonValue($json,"id") ;
	$table			= get_jsonValue($json,"table") ;
	$key			= get_jsonValue($json,"key") ;
	$name			= trim(get_jsonValue($json,"name")) ;
	if ($key == "")		$key = "id" ;
	
	sql_query("update `$table` set `name` = '$name' where `$key` = '$id'") ;
	
	$ret = array() ;	
	$ret['id']		= $id ;
	$ret['result'] 	= sql_fetch_one_cell("select `name` from `$table` where `$key` = '$id'") ;
	return $ret ;
}
// 更改某个表的图片数据
function test_change_table_images_value($json)
{
	$id 			= get_jsonValue($json,"id") ;
	$table			= get_jsonValue($json,"table") ;
	$field			= get_jsonValue($json,"field") ;
	$imgid			= get_jsonValue($json,"imgid") ;
	$key			= get_jsonValue($json,"key") ;
	$name			= trim(get_jsonValue($json,"name")) ;
	$onle			= intval(get_jsonValue($json,"onle")) ;		// 是否检测此图片在此表中只能有一个地方使用,如果其他地方用了,就不能再更改
	if ($key == "")		$key = "id" ;
	if ($name == "" || is_null($name))	$updatename = "" ;
	else 								$updatename = " , `name` = '$name' " ;
	
	$ret = array() ;	
	$ret['id']		= $id ;
	$ret['field'] 	= $field ;
	$ret['value'] 	= $imgid ;
	
	if ($field == 'small')	$ret['ty'] 	= 1 ;
	if ($field == 'thumb')	$ret['ty'] 	= 2 ;
	if ($field == 'url')	$ret['ty'] 	= 3 ;
	if ($field == 'all')	$ret['ty'] 	= 4 ;
	
	if ($imgid > 0 && $id > 0){
		if ($onle == 1){
			$find = sql_fetch_one("select * from `$table` where (`img_small_id` = '$imgid' or `img_thumb_id` = '$imgid' or `img_url_id` = '$imgid') and `$key` != '$id'") ;
			if (is_null($find) == false && is_array($find) == true){
				$ret['result'] = 0 ;
				$ret['memo'] = "此图片具有唯一性,已经被其他地方使用.请删除后重新加入装载." ;
				return $ret ;
			}
		}
		
		
		if ($field == 'small'){
			sql_query("update `$table` set `img_small_id` = '$imgid' $updatename where `$key` = '$id'") ;
			$ret['result'] = 1 ;
		}elseif ($field == 'thumb'){
			sql_query("update `$table` set `img_thumb_id` = '$imgid' $updatename where `$key` = '$id'") ;
			$ret['result'] = 1 ;
		}elseif ($field == 'url'){
			sql_query("update `$table` set `img_url_id` = '$imgid' $updatename where `$key` = '$id'") ;
			$ret['result'] = 1 ;
		}elseif ($field == 'all'){
			sql_query("update `$table` set `img_small_id` = '$imgid' , `img_thumb_id` = '$imgid' , `img_url_id` = '$imgid' $updatename where `$key` = '$id'") ;
			$ret['result'] = 1 ;
		}else{
			$ret['result'] = 0 ;
			$ret['memo'] = "属性错误,更改失败." ;
		}
	}else{
		$ret['result'] = 0 ;
		$ret['memo'] = "参数错误,更改失败." ;
	}
	return $ret ;
}
function test_insert_table_images_values($json)
{
	$table			= get_jsonValue($json,"table") ;
	$field			= get_jsonValue($json,"field") ;
	$imgid			= get_jsonValue($json,"imgid") ;
	$name			= get_jsonValue($json,"name") ;
	
	$ret = array() ;	
	
	if ($field == 'small')	$sqlfield = "img_small_id" ;
	if ($field == 'thumb')	$sqlfield = "img_thumb_id" ;
	if ($field == 'url')	$sqlfield = "img_url_id" ;
	
	$one = sql_fetch_one("select * from $table where $sqlfield = '$imgid'") ;
	if (is_array($one) && array_key_exists($sqlfield , $one)){
	}else{	
		$newid = sql_insert("insert into $table(`name` , `img_small_id` , `img_thumb_id` , `img_url_id`) values('$name','$imgid','$imgid','$imgid')") ;
		$one = sql_fetch_one("select * from $table where `id` = '$newid'") ;
	}
	$one['image'] = array() ;
	util_set_IMAGE($one['image'] , $one) ;
	$ret['result'] = $one ; 
	return $ret ;
	
}


// 删除一个首页信息推荐或轮播
function test_delete_from_sys_home_banner($json)
{
	$id 			= get_jsonValue($json,"id") ;
	if (sql_check("select `id` from `sys_home_banner` where `id` = '$id'")){
		sql_query("delete from `sys_home_banner` where `id` = '$id'") ;
	}
	$ret = array() ;
	$ret['result'] = sql_check("select `id` from `sys_home_banner` where `id` = '$id'") ? 0 : 1 ;
	$ret['del_id'] = $id ;
	return $ret ;
}

function test_get_itemlist($json)
{
	$pagination = get_jsonValue($json,"pagination") ;
	$offset = get_jsonValue($pagination,"offset") ;
	$limit  = get_jsonValue($pagination,"limit") ;
	$filter_name = trim(get_jsonValue($pagination,"filter_name")) ;
	
	$tzid = get_jsonValue($json,"tzid") ;
	$where = "" ;
	if ($tzid > 0){
		$where = "where `id` in (select item_id from taozhuang_pos where tzid = '$tzid')" ;
	}
	$item_id = get_jsonValue($json,"item_id") ;
	if ($item_id > 0){
		$where = "where `id` = '$item_id'" ;
	}
	
	$test = new test_bk() ;
	$ret = $test->get_table_for_page($offset , $limit , false , $filter_name , "sys_item" , $where) ;
	return $ret ;
}

function test_commit_item_material($json)
{
	$itemid = get_jsonValue($json,"id") ;
	$strids = trim(get_jsonValue($json,"ids")) ;
	if ($strids == "")	$strids = "0" ;
	
	sql_query("update sys_item set material_list = '$strids' where `id` = '$itemid'") ;
	sql_query("delete from base_sys_preview where `item_id` = '$itemid' and `mid` not in ($strids)") ;
	if ($strids == "0"){
		sql_query("delete from base_sys_preview where `item_id` = '$itemid'") ;	
	}
	
	$ret = array() ;
	$ret['result'] = sql_fetch_one_cell("select material_list from sys_item where `id` = '$itemid'") ;
	return $ret ;
}
function test_commit_item_fabric($json)
{
	$itemid = get_jsonValue($json,"id") ;
	$strids = trim(get_jsonValue($json,"ids")) ;
	if ($strids == "")	$strids = "0" ;
	
	sql_query("update sys_item set fabric_list = '$strids' where `id` = '$itemid'") ;
	if ($strids == "0"){
		sql_query("delete from base_sys_preview where `item_id` = '$itemid'") ;	
	}else{
		sql_query("delete from base_sys_preview where `item_id` = '$itemid' and `fid` not in ($strids)") ;
	}
	
	$ret = array() ;
	$ret['result'] = sql_fetch_one_cell("select fabric_list from sys_item where `id` = '$itemid'") ;
	return $ret ;
}
function test_commit_item_related($json)
{
	$itemid = get_jsonValue($json,"id") ;
	$strids = trim(get_jsonValue($json,"ids")) ;
	
	sql_query("update sys_item set related_list = '$strids' where `id` = '$itemid'") ;
	
	$ret = array() ;
	$ret['result'] = sql_fetch_one_cell("select related_list from sys_item where `id` = '$itemid'") ;
	return $ret ;
}
function test_get_material_for_ids($json)
{
	$strids = trim(get_jsonValue($json,"ids")) ;
	if ($strids == ""){
		$items = array() ;
	}else{
		$items = sql_fetch_rows("select * from base_sys_material where `id` in ($strids)") ;
	}
	
	foreach ($items as &$b){
		$b['image'] = array() ;
		util_set_IMAGE($b['image'] , $b) ;
	}
	
	$ret = array() ;
	$ret['data'] = $items ;	
	return $ret ;
}
function test_get_fabric_for_ids($json)
{
	$strids = trim(get_jsonValue($json,"ids")) ;
	if ($strids == ""){
		$items = array() ;
	}else{
		$items = sql_fetch_rows("select * from base_sys_fabric where `id` in ($strids)") ;
	}
	
	foreach ($items as &$b){
		$b['image'] = array() ;
		util_set_IMAGE($b['image'] , $b) ;
	}
	
	$ret = array() ;
	$ret['data'] = $items ;	
	return $ret ;
}
function test_set_item_f_m_nil($json)
{
	$itemid = trim(get_jsonValue($json,"itemid")) ;
	$table = trim(get_jsonValue($json,"table")) ;
	if ($table == "base_sys_fabric"){
		sql_query("update sys_item set fabric_list = '0' where `id` = '$itemid'") ;
		sql_query("delete from base_sys_preview where `item_id` = '$itemid' and fid > 0") ;
		$items = array() ;
		$items[] = array('id'=>0) ;
	}elseif ($table == "base_sys_material"){
		sql_query("update sys_item set material_list = '0' where `id` = '$itemid'") ;
		sql_query("delete from base_sys_preview where `item_id` = '$itemid' and mid > 0") ;
		$items = array() ;
		$items[] = array('id'=>0) ;
	}
	foreach ($items as &$b){
		$b['image'] = array() ;
		util_set_IMAGE($b['image'] , $b) ;
	}	
	$ret = array() ;
	$ret['data'] = $items ;	
	return $ret ;
}
function test_get_related_for_ids($json)
{
	$strids = trim(get_jsonValue($json,"ids")) ;
	if ($strids == ""){
		$items = array() ;
	}else{
		$items = sql_fetch_rows("select * from sys_item where `id` in ($strids)") ;
	}
	
	foreach ($items as &$b){
		$b['image'] = array() ;
		util_set_IMAGE($b['image'] , $b) ;
	}
	
	$ret = array() ;
	$ret['data'] = $items ;	
	return $ret ;
}

function test_get_fab_mat_item_all($json)
{
	$itemid = trim(get_jsonValue($json,"itemid")) ;
	
	$fms = sql_fetch_rows("select * from base_sys_preview where `item_id` = '$itemid'") ;
	foreach ($fms as &$f){
		$f['image'] = array() ;
		util_set_IMAGE($f['image'] , $f) ;
		$f['image_tz_url'] = array() ;
		util_set_IMAGE_one($f['image_tz_url'] , $f['img_tz_id']) ;
	}
	
	$ret = array() ;
	$ret['pre_list'] = $fms ;		
	return $ret ;
}
function test_change_preview_tz_id($json)
{
	$id 	= get_jsonValue($json,"id") ;
	$tzid 	= get_jsonValue($json,"tzid") ;
	sql_query("update base_sys_preview set img_tz_id = '$tzid' where `id` = '$id'") ;
	
	$ret = array() ;
	$ret['tzid'] = sql_fetch_one_cell("select img_tz_id from base_sys_preview where `id` = '$id'") ;
	return $ret ;
}
function test_get_fab_mat_item_one_info($json)
{
	$fid = trim(get_jsonValue($json,"fid")) ;
	$mid = trim(get_jsonValue($json,"mid")) ;
	
	$onefid = sql_fetch_one("select * from base_sys_fabric where `id` = '$fid'") ;
	if (is_array($onefid) && array_key_exists('id' , $onefid)){
		$onefid['image'] = array() ;
		util_set_IMAGE($onefid['image'] , $onefid) ;
	}else{
		$onefid = array() ;
	}
	
	$onemid = sql_fetch_one("select * from base_sys_material where `id` = '$mid'") ;
	if (is_array($onemid) && array_key_exists('id' , $onemid)){
		$onemid['image'] = array() ;
		util_set_IMAGE($onemid['image'] , $onemid) ;
	}else{
		$onemid = array() ;
	}
	
	$onefm = sql_fetch_one("select * from base_sys_preview where `fid` = '$fid' and `mid` = '$mid'") ;
	if (is_array($onefm) && array_key_exists('id' , $onefm)){
		$onefm['image'] = array() ;
		util_set_IMAGE($onefm['image'] , $onefm) ;
		$onefm['image_tz_url'] = array() ;
		util_set_IMAGE_one($onefm['image_tz_url'] , $onefm['img_tz_id']) ;
	}else{
		$onefm = array() ;
	}
	
	$ret = array() ;
	$ret['fabric'] = $onefid ;
	$ret['material'] = $onemid ;	
	$ret['preview'] = $onefm ;		
	return $ret ;
}
function test_insert_fab_mat_item_values($json)
{
	$imgid	= get_jsonValue($json,"imgid") ;
	$itemid = intval(get_jsonValue($json,"itemid")) ;
	$fid 	= trim(get_jsonValue($json,"fid")) ;
	$mid 	= trim(get_jsonValue($json,"mid")) ;
	
	$ret = array() ;	
	$newid = sql_insert("insert into base_sys_preview(`item_id` , `fid` , `mid` , `img_small_id` , `img_thumb_id` , `img_url_id`) values('$itemid','$fid','$mid','$imgid','$imgid','$imgid')") ;
	
	$onefm = sql_fetch_one("select * from base_sys_preview where `id` = '$newid'") ;
	if (is_array($onefm) && array_key_exists('id' , $onefm)){
		$onefm['image'] = array() ;
		util_set_IMAGE($onefm['image'] , $onefm) ;
		$onefm['image_tz_url'] = array() ;
		util_set_IMAGE_one($onefm['image_tz_url'] , $onefm['img_tz_id']) ;
	}else{
		$onefm = array() ;
	}
	
	$ret['result'] = $onefm ; 
	return $ret ;
}

function test_get_fat_mat_item_angle_values($json)
{
	$defid = intval(get_jsonValue($json,"id")) ;
	$list = sql_fetch_rows("select * from base_sys_preview_angle where `pid` = '$defid'") ;
	foreach ($list as &$f){
		$f['image'] = array() ;
		util_set_IMAGE($f['image'] , $f) ;
	}
	
	$ret = array() ;	
	$ret['list'] = $list ;
	return $ret ;
}
function test_insert_fat_mat_item_angle($json)
{
	$defid = intval(get_jsonValue($json,"id")) ;
	$imgid = intval(get_jsonValue($json,"imgid")) ;
	
	$newid = sql_insert("insert into base_sys_preview_angle(`pid` , `img_small_id` , `img_thumb_id` , `img_url_id`) values ('$defid' , '$imgid' , '$imgid' , '$imgid')") ;
	
	$one = sql_fetch_one("select * from base_sys_preview_angle where `id` = '$newid'") ;
	$one['image'] = array() ;
	util_set_IMAGE($one['image'] , $one) ;
	
	$ret = array() ;	
	$ret['result'] = $one ;
	
	return $ret ;
}
function test_delete_fat_mat_item_angle($json)
{
	$id = intval(get_jsonValue($json,"id")) ;
	sql_query("delete from base_sys_preview_angle where `id` = '$id'") ;
	
	$ret = array() ;	
	$ret['result'] = sql_check("select * from base_sys_preview_angle where `id` = '$id'") ? 0 : 1 ;
	
	return $ret ;
}
// 传递大图id,返回小图,中图,大图详细信息
function test_select_Big_image($json)
{
	$imgid = intval(get_jsonValue($json,"id")) ;
	
	$img = sql_fetch_one("select * from sys_image where `id` = '$imgid'") ;
	
	$imgurl = $img['url'] ;
	$dir = getPath_dir($imgurl) ;
	$fm  = getPath_name($imgurl) ;
	
	$findurl = $dir."thumb/".$fm ;
	$img_thumb = sql_fetch_one("select * from sys_image where `url` = '$findurl'") ;
	$findurl = $dir."small/".$fm ;
	$img_small = sql_fetch_one("select * from sys_image where `url` = '$findurl'") ;
	
	
	$img['url'] = $GLOBALS['URL_IMG_HEAD'] . $img['url'] ;
	$img_thumb['url'] = $GLOBALS['URL_IMG_HEAD'] . $img_thumb['url'] ;
	$img_small['url'] = $GLOBALS['URL_IMG_HEAD'] . $img_small['url'] ;
	$rnt = array() ;	
	$rnt['url'] = $img ;
	$rnt['thumb'] = $img_thumb ;
	$rnt['small'] = $img_small ;
	return $rnt ;
}
// 获取所有分类信息
function test_get_grp_class()
{
	$ret = array() ;
	$ret['result'] = sql_fetch_rows("select * from grp_class") ;
	return $ret ;
}
function test_get_grp_space()
{
	$ret = array() ;
	$ret['result'] = sql_fetch_rows("select * from grp_space") ;
	return $ret ;
}
function test_get_grp_style()
{
	$ret = array() ;
	$ret['result'] = sql_fetch_rows("select * from grp_style") ;
	return $ret ;
}
// 删除一个分类信息
function test_del_grp_class($json)
{
	$id = (get_jsonValue($json,"id")) ;
	test_del_idandchildall($id , "grp_class") ;
	$ret = array() ;
	$ret['result'] = sql_fetch_rows("select * from grp_class") ;
	return $ret ;
}
function test_del_grp_space($json)
{
	$id = (get_jsonValue($json,"id")) ;
	test_del_idandchildall($id , "grp_space") ;
	$ret = array() ;
	$ret['result'] = sql_fetch_rows("select * from grp_space") ;
	return $ret ;
}
function test_del_grp_style($json)
{
	$id = (get_jsonValue($json,"id")) ;
	test_del_idandchildall($id , "grp_style") ;
	$ret = array() ;
	$ret['result'] = sql_fetch_rows("select * from grp_style") ;
	return $ret ;
}
function test_del_idandchildall($myid , $tablename)
{
	$all = sql_fetch_rows("select * from $tablename where father = '$myid'") ;
	foreach ($all as $a){
		test_del_idandchildall($a['id'] , $tablename);
	}
	sql_query("delete from $tablename where `id` = '$myid'") ;	
}
// 修改一个分类信息
function test_update_grp_class($json)
{
	$id = (get_jsonValue($json,"id")) ;
	$name = get_jsonValue($json,"name") ;
	$idx = intval(get_jsonValue($json,"idx")) ;
	
	sql_query("update grp_class set `name` = '$name' where `id` = '$id'") ;
	sql_query("update `prf_type` set `typename` = '$name' where `id` = '$id'") ;
	
	
	$rnt = array() ;
	$rnt['result'] = 1 ;	
	$rnt['idx'] = $idx ;
	$rnt['data'] = sql_fetch_one("select * from grp_class where `id` = '$id'") ;
	return $rnt ;
}
function test_update_grp_space($json)
{
	$id = (get_jsonValue($json,"id")) ;
	$name = get_jsonValue($json,"name") ;
	$idx = intval(get_jsonValue($json,"idx")) ;

	sql_query("update grp_space set `name` = '$name' where `id` = '$id'") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;	
	$rnt['idx'] = $idx ;
	$rnt['data'] = sql_fetch_one("select * from grp_space where `id` = '$id'") ;
	return $rnt ;
}
function test_update_grp_style($json)
{
	$id = (get_jsonValue($json,"id")) ;
	$name = get_jsonValue($json,"name") ;
	$idx = intval(get_jsonValue($json,"idx")) ;

	sql_query("update grp_style set `name` = '$name' where `id` = '$id'") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;	
	$rnt['idx'] = $idx ;
	$rnt['data'] = sql_fetch_one("select * from grp_style where `id` = '$id'") ;
	return $rnt ;
}
// 添加一个分类信息
function test_add_grp_class($json)
{
	$fid = (get_jsonValue($json,"fid")) ;	// 父id
	$name = get_jsonValue($json,"name") ;
	$idx = intval(get_jsonValue($json,"idx")) ;
	
	return __test_add_grp_ty($fid , $name , $idx , "grp_class") ;
}
function test_add_grp_space($json)
{
	$fid = (get_jsonValue($json,"fid")) ;	// 父id
	$name = get_jsonValue($json,"name") ;
	$idx = intval(get_jsonValue($json,"idx")) ;
	
	return __test_add_grp_ty($fid , $name , $idx , "grp_space") ;
}
function test_add_grp_style($json)
{
	$fid = (get_jsonValue($json,"fid")) ;	// 父id
	$name = get_jsonValue($json,"name") ;
	$idx = intval(get_jsonValue($json,"idx")) ;
	
	return __test_add_grp_ty($fid , $name , $idx , "grp_style") ;
}
function __test_add_grp_ty($fid , $name , $idx , $tablename)
{
	$all = sql_fetch_rows("select * from $tablename where father = '$fid' order by `id` asc") ;

	$first = 1 ;	
	$exist = true ;
	while ($exist){
		$exist = false ;
		foreach ($all as $a){
			$id = floor($a['id'] / (pow(10 , (5 - $idx) * 2))) % 100 ;
			if ($first == $id){
				$first += 1 ;
				$exist = true ;
				break ;
			}
		}
	}
	$fid = doubleval($fid) ;
	if ($fid == 0){
		if ($first <= 20){
			$newid = $fid + $first * (pow(10 , (5 - $idx) * 2)) ;
		}else{
			$ret = array() ;
			$ret['result'] =  -1 ;
			$ret['mess'] = "添加错误" ;
			return $ret ;
		}
	}elseif ($first <= 99){
		$newid = $fid +  $first * (pow(10 , (5 - $idx) * 2)) ;
	}else{
		$ret = array() ;
		$ret['result'] =  -1 ;
		$ret['mess'] = "添加错误" ;
		return $ret ;
	}
	
	sql_insert("insert into $tablename(`id`,`name`,`father`) values('$newid' , '$name' , '$fid')") ;
	if ($tablename == "grp_class"){
		sql_insert("INSERT INTO `prf_type` (`id`,`typename`, `father`) VALUES ('$newid','$name','$fid')") ;
	}
	
	
	$rnt = array() ;
	$rnt['result'] = 1 ;	
	$rnt['idx'] = $idx ;
	$rnt['data'] = sql_fetch_one("select * from $tablename where `id` = '$newid'") ;
	return $rnt ;
}
// 设置记录置顶
function test_edit_toTop($json)
{
	$id = get_jsonValue($json,"id") ;
	$table = get_jsonValue($json,"table") ;

	$feild = "id" ;
	if ($table == "taozhuang")	$feild = "sid" ;
	
	sql_query("update `$table` set `top_time` = unix_timestamp() where $feild = '$id'") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;
	return $rnt ;
}
// 取消记录置顶
function test_del_toTop($json)
{
	$id = get_jsonValue($json,"id") ;
	$table = get_jsonValue($json,"table") ;

	$feild = "id" ;
	if ($table == "taozhuang")	$feild = "sid" ;
	
	sql_query("update `$table` set `top_time` = 0 where $feild = '$id'") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;
	return $rnt ;
}
// 添加一个新的秀家信息
function test_add_show()
{
	sql_insert("insert into `show`(`name` , `app_return`,`publish_time`) values ('新建秀家图' , '0',unix_timestamp())") ;
	$rnt = array() ;
	$rnt['result'] = 1 ;
	return $rnt ;
}
// 添加一个秀家位置
function test_add_showpos($json)
{
	$id = (get_jsonValue($json,"id")) ;	// id
	sql_insert("insert into `show_pos`(`sid` , `posx` , `posy`) values ('$id' , '50' , '50')") ;
	$rnt = array() ;
	$rnt['result'] = 1 ;
	return $rnt ;
}
// 删除一个新的秀家信息
function test_del_show($json)
{
	$id = (get_jsonValue($json,"id")) ;	// id
	sql_query("delete from `show` where `id` = '$id'") ;
	sql_query("delete from `show_pos` where `sid` = '$id'") ;
	sql_query("delete from `show_color` where `show_id` = '$id'") ;
	sql_query("delete from `show_style` where `show_id` = '$id'") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;
	return $rnt ;
}
// 删除一个新的秀家信息
function test_del_showpos($json)
{
	$id = (get_jsonValue($json,"id")) ;	// id
	sql_query("delete from `show_pos` where `id` = '$id'") ;
	$rnt = array() ;
	$rnt['result'] = 1 ;
	return $rnt ;
}
// 编辑一个秀家
function test_edit_show($json)
{
	$id = get_jsonValue($json,"id") ;
	$nm = get_jsonValue($json,"name") ;
	$app_return =  get_jsonValue($json,"app_return") ;
	$space_id =  get_jsonValue($json,"space_id") ;
	
	sql_query("update `show` set `name` = '$nm',`app_return` = '$app_return',`space_id` = '$space_id' where `id` = '$id'") ;
	sql_query("delete from `show_style` where `show_id` = '$id'") ;
	sql_query("delete from `show_color` where `show_id` = '$id'") ;
	
	$style_arr = get_jsonValue($json,"style_arr") ;
	foreach ($style_arr as $sy){
		sql_insert("INSERT INTO `show_style` (`show_id` , `style_id`) values ('$id' , '$sy') ON DUPLICATE KEY UPDATE `style_id` = '$sy'") ;
	}
	$color_arr = get_jsonValue($json,"color_arr") ;
	foreach ($color_arr as $sy){
		sql_insert("INSERT INTO `show_color` (`show_id` , `color_id`) values ('$id' , '$sy') ON DUPLICATE KEY UPDATE `color_id` = '$sy'") ;
	}

	$rnt = array() ;
	$rnt['result'] = 1 ;
	return $rnt ;
}
// 编辑一个秀家位置信息
function test_edit_showpos($json)
{
	$id 	= get_jsonValue($json,"id") ;
	$posx 	= get_jsonValue($json,"posx") ;
	$posy 	= get_jsonValue($json,"posy") ;
	$url	= get_jsonValue($json,"url") ;
	$action	= get_jsonValue($json,"action") ;
	
	$addsql = "" ;
	if ($action == 'set' || $action == 'item'){
		$action_id = intval($url) ;
		$addsql = " , `action` = '$action' , `action_id` = '$action_id' " ;
	}else{
		$addsql = " , `action` = '' , `action_id` = '0' , `url` = '$url' " ;
	}
	
	sql_query("update `show_pos` set `posx` = '$posx' , `posy` = '$posy' $addsql where `id` = '$id'") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;
	return $rnt ;
}
// 获取套装额外过滤属性
function test_get_show_exparam($json)
{
	$id = get_jsonValue($json,"tzid") ;
	$ret = array() ;
	$ret['color'] = sql_fetch_rows("select * from show_color where show_id = '$id'") ;
	$ret['style'] = sql_fetch_rows("select * from show_style where show_id = '$id'") ;
	return $ret ;
}

/**
 * 获取所有有透视图的单品
 */
function test_item_gethavetslist(&$json)
{
	$pagination = get_jsonValue($json,"pagination") ;
	$offset = get_jsonValue($pagination,"offset") ;		if (intval($offset) < 1)	$offset = 1 ;
	$limit  = get_jsonValue($pagination,"limit") ;		if (intval($limit) < 1)		$limit = 20 ;
	$start = ($offset - 1) * $limit ;	
	
	$filter_name = trim(get_jsonValue($json,"filter_name")) ;
	$nm_ft = "" ;
	if ($filter_name != ""){
		$nm_ft = " and s.`name` like '%$filter_name%'" ;
	}
	
	$allcount = sql_fetch_one_cell("select count(s.id) from sys_item s inner join base_sys_preview b on s.id = b.item_id where b.img_tz_id > 0 $nm_ft") ;
	$list = sql_fetch_rows("select s.* from sys_item s inner join base_sys_preview b on s.id = b.item_id where b.img_tz_id > 0 $nm_ft  group by s.id order by s.top_time desc , s.update_at desc , s.id desc limit $start , $limit") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;
	$rnt['list'] = $list ;
	
	$rnt['pagination'] = array() ;
	util_set_PAGINATION($rnt['pagination'] , $allcount , $limit , $offset) ;
	
	return $rnt ;
}
function test_item_get_preview(&$json)
{
	$id = get_jsonValue($json,"id") ;
	
	$list = sql_fetch_rows("select b.id , b.item_id , CONCAT('{$GLOBALS['URL_IMG_HEAD']}' , s.`url`) as url from base_sys_preview b left join sys_image s on b.img_tz_id = s.id where b.item_id = '$id' and b.img_tz_id > 0") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;
	$rnt['list'] = $list ;
	return $rnt ;
}
function test_item_anchor_update($json)
{
	$id = get_jsonValue($json,"id") ;
	$anchor_x 	= doubleval(get_jsonValue($json, "anchor_x")) ;
	$anchor_y 	= doubleval(get_jsonValue($json, "anchor_y")) ;
	
	sql_query("update sys_item set anchor_x = '$anchor_x' , anchor_y = '$anchor_y' where `id` = '$id'") ;
	
	$rnt = array() ;
	$rnt['result'] = 1 ;
	$rnt['anchor_x'] = $anchor_x ;
	$rnt['anchor_y'] = $anchor_y ;
	return $rnt ;
}
/**
// TODO 这个是测试接口  , 使用需要打开.
function test_test_insert_taozhuang_pos_to_sys_item(){		return ;
	$list = sql_fetch_rows("select * from taozhuang_pos") ;
	foreach ($list as $t){
		test_taozhuang_id_item_id_dy($t['id'] , $t['img_id']) ;
	}
	$ret = array() ;
	$ret['result'] = "ok" ;
	return $ret ;
}
function test_test_insert_taozhuang_pos_to_sys_item2(){		return ;
	$list = sql_fetch_rows("select * from sys_item where `id` > 8") ;
	foreach ($list as $t){
		$id = $t['id'] ;
		if (sql_check("select * from taozhuang_pos where item_id = '$id'") == false){
			sql_query("delete from sys_item where `id` = '$id'") ;
		}
	}
	$ret = array() ;
	$ret['result'] = "ok" ;
	return $ret ;
}
function test_test_get_sys_img(){		return ;
	$list = sql_fetch_rows("select * from sys_image") ;
	$ret = array() ;
	$ret['result'] = $list ;
	return $ret ;
}
function test_test_change_img_wh($json){		return ;
	$id = get_jsonValue($json,"id") ;
	$w = get_jsonValue($json,"w") ;
	$h = get_jsonValue($json,"h") ;
	
	sql_query("update `sys_image` set `width` = '$w' , `height` = '$h' where `id` = '$id'") ;
	
	$ret = array() ;
	$ret['result'] = "ok" ;
	return $ret ;
}
**/

?>